package org.example.core.enums;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 结果返回类
 */
@JsonInclude
public class ApiResult {

    private String code;

    private String msg;

    private Object data;
    /**
     * 判断是否是系统级错误
     */
    private boolean success;

    public ApiResult(String code, String msg, Object data, boolean success) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.success = success;
    }

    public static ApiResult success(Object data) {
        return new ApiResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data, Boolean.TRUE);
    }

    public static ApiResult success() {
        return new ApiResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null, Boolean.TRUE);
    }

    public static ApiResult failure(Object data) {
        return new ApiResult(ResultEnum.FAILURE.getCode(), ResultEnum.FAILURE.getMsg(), data, Boolean.TRUE);
    }

    public static ApiResult failure(String msg) {
        return new ApiResult(ResultEnum.FAILURE.getCode(), msg, null, Boolean.TRUE);
    }

    public static ApiResult failure(String msg,Object data) {
        return new ApiResult(ResultEnum.FAILURE.getCode(), msg, data, Boolean.TRUE);
    }

    public static ApiResult failure() {
        return new ApiResult(ResultEnum.FAILURE.getCode(), ResultEnum.FAILURE.getMsg(), null, Boolean.TRUE);
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
